From a8d54496fb0a642ff3dd6c3bf4c5ee8340e33669 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Wed, 3 Oct 2001 15:08:10 +0000 Subject: [PATCH] Allow NUOL for @target_list to mean, use gtk_drag_dest_get_target_list Wed Oct 3 10:42:54 2001 Owen Taylor * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow NUOL for @target_list to mean, use gtk_drag_dest_get_target_list (widget). * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where drop could hang when calling gtk_drag_finish with success == FALSE and del == TRUE. * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where drops without a matching target found would propagate to the parent widget rather than being rejected. * gtk/gtktextview.c (gtk_text_view_drag_data_received): Use text_view->dnd_mark instead of mark name to be consistent with the rest of the code. * gtk/gtktextview.c (gtk_text_view_drag_motion): Make pendantically correct for a drop-only-in-some-places widget. (Check whether you can insert in drag_drop, not just in drag_motion ... matters in theory, and for Motif drag and drop in practice.) * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from Damian Ivereigh to not allow drops on non-editable entries. (#61124) * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow text to be moved from a non-editable entry. --- ChangeLog | 31 ++++++++++++++++ ChangeLog.pre-2-0 | 31 ++++++++++++++++ ChangeLog.pre-2-10 | 31 ++++++++++++++++ ChangeLog.pre-2-2 | 31 ++++++++++++++++ ChangeLog.pre-2-4 | 31 ++++++++++++++++ ChangeLog.pre-2-6 | 31 ++++++++++++++++ ChangeLog.pre-2-8 | 31 ++++++++++++++++ gtk/gtkdnd.c | 28 ++++++++++----- gtk/gtkentry.c | 90 ++++++++++++++++++++++++++++++++++------------ gtk/gtktextview.c | 39 +++++++++++++++----- 10 files changed, 335 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 54201f203d..33b3bb6ce6 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,34 @@ +Wed Oct 3 10:42:54 2001 Owen Taylor + + * gtk/gtkdnd.c (gtk_drag_dest_find_target): Allow + NUOL for @target_list to mean, use + gtk_drag_dest_get_target_list (widget). + + * gtk/gtkdnd.c (gtk_drag_finish): Fix problem where + drop could hang when calling gtk_drag_finish with + success == FALSE and del == TRUE. + + * gtk/gtkdnd.c (gtk_drag_dest_drop): Fix problem where + drops without a matching target found would propagate + to the parent widget rather than being rejected. + + * gtk/gtktextview.c (gtk_text_view_drag_data_received): + Use text_view->dnd_mark instead of mark name to be + consistent with the rest of the code. + + * gtk/gtktextview.c (gtk_text_view_drag_motion): Make + pendantically correct for a drop-only-in-some-places + widget. (Check whether you can insert in drag_drop, + not just in drag_motion ... matters in theory, and + for Motif drag and drop in practice.) + + * gtk/gtkentry.c (gtk_entry_drag_drop): Patch from + Damian Ivereigh to not allow drops on non-editable + entries. (#61124) + + * gtk/gtkentry.c (gtk_entry_motion_notify): Don't allow + text to be moved from a non-editable entry. + 2001-10-03 James Henstridge * gtk/gtktreeviewcolumn.c (gtk_tree_view_column_set_fixed_width): diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index f61ae769f2..95a63df5e5 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -699,7 +699,7 @@ gtk_drag_finish (GdkDragContext *context, time); } - if (!del) + if (!(success && del)) gdk_drop_finish (context, success, time); } @@ -1061,7 +1061,8 @@ _gtk_drag_dest_handle_event (GtkWidget *toplevel, * gtk_drag_dest_find_target: * @widget: drag destination widget * @context: drag context - * @target_list: list of droppable targets + * @target_list: list of droppable targets, or %NULL to use + * gtk_drag_dest_get_target_list (@widget). * * Looks for a match between @context->targets and the * @dest_target_list, returning the first matching target, otherwise @@ -1080,8 +1081,16 @@ gtk_drag_dest_find_target (GtkWidget *widget, { GList *tmp_target; GList *tmp_source = NULL; - GtkWidget *source_widget = gtk_drag_get_source_widget (context); + GtkWidget *source_widget; + g_return_val_if_fail (GTK_IS_WIDGET (widget), GDK_NONE); + g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), GDK_NONE); + + source_widget = gtk_drag_get_source_widget (context); + + if (target_list == NULL) + target_list = gtk_drag_dest_get_target_list (widget); + if (target_list == NULL) return GDK_NONE; @@ -1569,7 +1578,7 @@ gtk_drag_dest_motion (GtkWidget *widget, } } - if (action && gtk_drag_dest_find_target (widget, context, site->target_list)) + if (action && gtk_drag_dest_find_target (widget, context, NULL)) { if (!site->have_drag) { @@ -1676,12 +1685,15 @@ gtk_drag_dest_drop (GtkWidget *widget, if (site->flags & GTK_DEST_DEFAULT_DROP) { - GdkAtom target = gtk_drag_dest_find_target (widget, context, site->target_list); + GdkAtom target = gtk_drag_dest_find_target (widget, context, NULL); if (target == GDK_NONE) - return FALSE; - - gtk_drag_get_data (widget, context, target, time); + { + gtk_drag_finish (context, FALSE, FALSE, time); + return TRUE; + } + else + gtk_drag_get_data (widget, context, target, time); } gtk_signal_emit_by_name (GTK_OBJECT (widget), "drag_drop", diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index d95f27c677..5e48c489af 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -146,6 +146,11 @@ static void gtk_entry_direction_changed (GtkWidget *widget, static void gtk_entry_state_changed (GtkWidget *widget, GtkStateType previous_state); +static gboolean gtk_entry_drag_drop (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time); static gboolean gtk_entry_drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, @@ -380,6 +385,7 @@ gtk_entry_class_init (GtkEntryClass *class) widget_class->state_changed = gtk_entry_state_changed; widget_class->mnemonic_activate = gtk_entry_mnemonic_activate; + widget_class->drag_drop = gtk_entry_drag_drop; widget_class->drag_motion = gtk_entry_drag_motion; widget_class->drag_leave = gtk_entry_drag_leave; widget_class->drag_data_received = gtk_entry_drag_data_received; @@ -908,7 +914,7 @@ gtk_entry_init (GtkEntry *entry) entry->has_frame = TRUE; gtk_drag_dest_set (GTK_WIDGET (entry), - GTK_DEST_DEFAULT_DROP | GTK_DEST_DEFAULT_HIGHLIGHT, + GTK_DEST_DEFAULT_HIGHLIGHT, target_table, G_N_ELEMENTS (target_table), GDK_ACTION_COPY | GDK_ACTION_MOVE); @@ -1525,8 +1531,9 @@ gtk_entry_motion_notify (GtkWidget *widget, { GdkDragContext *context; GtkTargetList *target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table)); + guint actions = entry->editable ? GDK_ACTION_COPY | GDK_ACTION_MOVE : GDK_ACTION_COPY; - context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY | GDK_ACTION_MOVE, + context = gtk_drag_begin (widget, target_list, actions, entry->button, (GdkEvent *)event); @@ -3822,6 +3829,29 @@ gtk_entry_drag_leave (GtkWidget *widget, gtk_widget_queue_draw (widget); } +static gboolean +gtk_entry_drag_drop (GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time) +{ + GtkEntry *entry; + GdkAtom target = GDK_NONE; + + entry = GTK_ENTRY (widget); + + if (entry->editable) + target = gtk_drag_dest_find_target (widget, context, NULL); + + if (target != GDK_NONE) + gtk_drag_get_data (widget, context, target, time); + else + gtk_drag_finish (context, FALSE, FALSE, time); + + return TRUE; +} + static gboolean gtk_entry_drag_motion (GtkWidget *widget, GdkDragContext *context, @@ -3843,31 +3873,40 @@ gtk_entry_drag_motion (GtkWidget *widget, old_position = entry->dnd_position; new_position = gtk_entry_find_position (entry, x + entry->scroll_offset); - source_widget = gtk_drag_get_source_widget (context); - suggested_action = context->suggested_action; - - if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) || - new_position < sel1 || new_position > sel2) + if (entry->editable) { - if (source_widget == widget) - { - /* Default to MOVE, unless the user has - * pressed ctrl or alt to affect available actions - */ - if ((context->actions & GDK_ACTION_MOVE) != 0) - suggested_action = GDK_ACTION_MOVE; - } + source_widget = gtk_drag_get_source_widget (context); + suggested_action = context->suggested_action; + + if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &sel1, &sel2) || + new_position < sel1 || new_position > sel2) + { + if (source_widget == widget) + { + /* Default to MOVE, unless the user has + * pressed ctrl or alt to affect available actions + */ + if ((context->actions & GDK_ACTION_MOVE) != 0) + suggested_action = GDK_ACTION_MOVE; + } + + entry->dnd_position = new_position; + } + else + { + if (source_widget == widget) + suggested_action = 0; /* Can't drop in selection where drag started */ - entry->dnd_position = new_position; + entry->dnd_position = -1; + } } else { - if (source_widget == widget) - suggested_action = 0; /* Can't drop in selection where drag started */ - + /* Entry not editable */ + suggested_action = 0; entry->dnd_position = -1; } - + gdk_drag_status (context, suggested_action, time); if (entry->dnd_position != old_position) @@ -3894,7 +3933,7 @@ gtk_entry_drag_data_received (GtkWidget *widget, str = gtk_selection_data_get_text (selection_data); - if (str) + if (str && entry->editable) { gint new_position; gint sel1, sel2; @@ -3914,6 +3953,12 @@ gtk_entry_drag_data_received (GtkWidget *widget, } g_free (str); + gtk_drag_finish (context, TRUE, context->action == GDK_ACTION_MOVE, time); + } + else + { + /* Drag and drop didn't happen! */ + gtk_drag_finish (context, FALSE, FALSE, time); } } @@ -3947,7 +3992,8 @@ gtk_entry_drag_data_delete (GtkWidget *widget, GtkEditable *editable = GTK_EDITABLE (widget); - if (gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end)) + if (GTK_ENTRY (widget)->editable && + gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end)) gtk_editable_delete_text (editable, sel_start, sel_end); } diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index d3dfd9d738..43613bd448 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -955,7 +955,7 @@ gtk_text_view_init (GtkTextView *text_view) text_view->editable = TRUE; gtk_drag_dest_set (widget, - GTK_DEST_DEFAULT_DROP, + 0, target_table, G_N_ELEMENTS (target_table), GDK_ACTION_COPY | GDK_ACTION_MOVE); @@ -4903,6 +4903,8 @@ gtk_text_view_drag_drop (GtkWidget *widget, guint time) { GtkTextView *text_view; + GtkTextIter drop_point; + GdkAtom target = GDK_NONE; text_view = GTK_TEXT_VIEW (widget); @@ -4912,7 +4914,19 @@ gtk_text_view_drag_drop (GtkWidget *widget, text_view->scroll_timeout = 0; gtk_text_mark_set_visible (text_view->dnd_mark, FALSE); - + + gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), + &drop_point, + text_view->dnd_mark); + + if (gtk_text_iter_can_insert (&drop_point, text_view->editable)) + target = gtk_drag_dest_find_target (widget, context, NULL); + + if (target != GDK_NONE) + gtk_drag_get_data (widget, context, target, time); + else + gtk_drag_finish (context, FALSE, FALSE, time); + return TRUE; } @@ -4945,19 +4959,19 @@ gtk_text_view_drag_data_received (GtkWidget *widget, { GtkTextIter drop_point; GtkTextView *text_view; - GtkTextMark *drag_target_mark; + gboolean success = FALSE; text_view = GTK_TEXT_VIEW (widget); - drag_target_mark = gtk_text_buffer_get_mark (get_buffer (text_view), - "gtk_drag_target"); - - if (drag_target_mark == NULL) - return; + if (!text_view->dnd_mark) + goto done; gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &drop_point, - drag_target_mark); + text_view->dnd_mark); + + if (!gtk_text_iter_can_insert (&drop_point, text_view->editable)) + goto done; if (selection_data->target == gdk_atom_intern ("GTK_TEXT_BUFFER_CONTENTS", FALSE)) { @@ -5003,6 +5017,13 @@ gtk_text_view_drag_data_received (GtkWidget *widget, } else insert_text_data (text_view, &drop_point, selection_data); + + success = TRUE; + + done: + gtk_drag_finish (context, success, + success && context->action == GDK_ACTION_MOVE, + time); } static GtkAdjustment* -- 2.30.2